package com.songshuai.webapi.baseapi.enumerations.miniprogram;


public enum ResponseStatus {
    // -1为通用失败（根据ApiResult.java中的构造方法注释而来）
    FAIL(-1, "common fail"),
    FAILOfficial(1, "common fail"),
    // 0为成功
    SUCCESS(0, ""),
    ACCESS_TOKEN_ERRCODE(-1,"系统繁忙，此时请开发者稍候再试"),
    ACCESS_TOKEN_ERRCODE_40001(40001,"AppSecret 错误或者 AppSecret 不属于这个小程序，请开发者确认 AppSecret 的正确性"),
    ACCESS_TOKEN_ERRCODE_40002(40002,"请确保 grant_type 字段值为 client_credential"),
    ACCESS_TOKEN_ERRCODE_40013(40013,"请确保 grant_type 字段值为 client_credential");

    private int code;
    private String msg;

    ResponseStatus(int code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public static int getCode(String define){
        try {
            return ResponseStatus.valueOf(define).code;
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return FAIL.getErrorCode();
        }
    }

    public static String getMsg(String define){
        try {
            return ResponseStatus.valueOf(define).msg;
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
            return FAIL.getErrorMsg();
        }
    }

    public static String getMsg(int code){
        for(ResponseStatus err : ResponseStatus.values()){
            if(err.code==code){
                return err.msg;
            }
        }
        return "errorCode not defined ";
    }

    public int getErrorCode(){
        return code;
    }

    public String getErrorMsg(){
        return msg;
    }
}
